2 Problem: 10054 - The Necklace
3 Andrés Mejía-Posada (andmej@gmail.com)
26 #define D(x) cout << #x " is " << x << endl
31 int adj
[MAXN
][MAXN
], degree
[MAXN
];
35 void visit_component(int u
){
36 if (visited
[u
]) return;
38 for (int v
=0; v
<n
; ++v
){
39 if (adj
[u
][v
]) visit_component(v
);
43 void find_euler_path(int u
){
44 for (int v
=0; v
<n
; ++v
){
46 adj
[u
][v
]--, adj
[v
][u
]--;
56 for (int t
=1; t
<=T
; ++t
){
57 if (t
> 1) printf("\n");
58 printf("Case #%d\n", t
);
60 bzero(visited
, sizeof visited
);
61 bzero(adj
, sizeof adj
);
62 bzero(degree
, sizeof degree
);
67 for(scanf("%d", &edges
); edges
--; ){
69 scanf("%d %d", &u
, &v
);
72 degree
[u
]++, degree
[v
]++;
73 adj
[u
][v
]++, adj
[v
][u
]++;
76 for (int i
=0; i
<n
; ++i
){
83 bool impossible
= false;
84 for (int i
=0; i
<n
; ++i
){
85 if (degree
[i
] > 0 && !visited
[i
] || degree
[i
] % 2 == 1){
92 for (int i
=0; i
<n
; ++i
){
101 printf("some beads may be lost\n");
103 for (int i
=0; i
<path
.size()-1; ++i
){
104 printf("%d %d\n", path
[i
], path
[i
+1]);